﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KCMS.DataAcsess.Interfaces;
using KCMS.DataAcsess.Entitys;

namespace KCMS.DataAcsess.Engine
{
    public class MenuManager : IMenuManager
    {
        protected DataClassesDataContext db = new DataBaseConnect().DataBase;

        private DataManager<MenuEntity> dm = new DataManager<MenuEntity>();
        public MenuEntity getById(Guid id)
        {
            return (from t in db.GetTable<MenuEntity>()
                    where t.Id.Equals(id)
                    select t).SingleOrDefault();

        }
        public IEnumerable<MenuEntity> getAll()
        {
            //return (from t in db.GetTable<MenuEntity>()
            //        select t).ToList();
            return dm.getAll();
        }




        public void update(MenuEntity menu)
        {
            db = new DataBaseConnect().DataBase;
            var old = getById(menu.Id);
            old.CopyPropyties(menu);
            db.SubmitChanges();
        }

        public void delete(Guid id)
        {
            dm.delete(id);
        }

        public void save(MenuEntity menu)
        {
            dm.save(menu);
        }
    }
}
